//
// Created by DengLibin on 2018/12/12 0012.
//

#include <iostream>
#include <string>
#include <iomanip>
#include <string.h>
using namespace std;
//标准输入流
void testCin()
{
    char buf[1024];
    int i;
    long l;
    double d;
    cin >> i;
    cin >> l;
    cin >> d;
    cin >> buf;//遇到空格就结束，空格后面的字符不会进数组
    cout << i << endl;
    cout << l << endl;
    cout << d << endl;
    cout << buf << endl;
}
//cin.get()
void testCinGet()
{
    char c;
    //能够读取空白(空格，制表，换行)赋值给字符变量,返回类型为int。使用方法 char ch; ch=cin.get();
    while ((c = cin.get()) != EOF)//可以输入多个字符串，会放到缓冲区，(回车键结束输入，开始取字符，回车也是字符)每循环一次从缓冲区取一个字符，取完后会阻塞，ctrl + z退出
    {
        cout << "c=" << c << endl;
    }
}
//cin.get(char c)
void testCinGetChar()
{
    char a, b, c;
    cin.get(a).get(b).get(c);//输入字符串到缓冲区，然后获取前三个字符分别复制给a b c若 缓冲区不足三个字符，会阻塞(每get一次获取缓冲区的下一个字符)
    cout << a << endl;
    cout << b << endl;
    cout << c << endl;
}
//cin.getLine(char*,len)
void testCinGetLine()
{
    char buf[256];
    cin.getline(buf, sizeof(buf));//接收一个字符串，可以接收空格并输出
    cout << buf << endl;
    string s = "我的";
    string s1 = "my";
    cout << s.length() << endl;//4
    cout << s1.length() << endl; //2
}
//标准输出流
void testCout()
{
    cout << "hello world" << endl;
    cout.put('h').put('e').put('l');//将字符输出到标准输出设备
    cout << endl;
    string s = "hello world";
    const char *p = s.c_str();
    cout.write(p,strlen(p));
    cout << endl;
    cout.write(p,strlen(p)-4);
    cout << endl;
    cout.write(p,strlen(p)+4);
    cout << endl;
    cout << hex << 123 << endl;//16进制
    cout << "<Start>"
         << setw(30)
         << setfill('*')
         << setiosflags(ios::showbase) //基数
         << setiosflags(ios::internal)
         << hex
         << 123
         << "<End>\n";

    int a;
    cout << "input a:";
    cin >> a;
    cout << "dec:" << dec << a << endl; //以十进制形式输出整数
    cout << "hex:" << hex << a << endl; //以十六进制形式输出整数a
    cout << "oct:" << setbase(8) << a << endl; //以八进制形式输出整数a
    string ss = "China";
    const char *pt = ss.c_str(); //pt指向字符串"China"
    cout << setw(10) << pt << endl; //指定域宽为,输出字符串
    cout << setfill('*') << setw(10) << pt << endl; //指定域宽,输出字符串,空白处以'*'填充
    double pi = 22.0 / 7.0; //计算pi值
    //按指数形式输出,8位小数
    cout << setiosflags(ios::scientific) << setprecision(8);
    cout << "pi=" << pi << endl; //输出pi值
    cout << "pi=" << setprecision(4) << pi << endl; //改为位小数
    cout << "pi=" << setiosflags(ios::fixed) << pi << endl; //改为小数形式输出

}
int main15(int argc, char * argv[])
{
    //testCin();
    //testCinGet();
    //testCinGetChar();
    //testCinGetLine();
    testCout();
    system("pause");
    return 0;
}